package com.jinhua.batch.model;

import com.alibaba.fastjson.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty;

import java.util.Objects;

/**
 * Copyright
 *
 * @Author WuHuang
 * @Date 2023/3/31
 */

public class BatchProcessRequest<T extends ResultItemVO> {
    @ApiModelProperty(
            required = true,
            value = "用户上传的excel的下载地址"
    )
    private String excelUrl;
    @ApiModelProperty(
            required = true,
            value = "任务id，用于后续查询当前任务的状态"
    )
    private String taskId;
    @JSONField(
            serialize = false
    )
    @ApiModelProperty(
            required = true,
            value = "split之后的调用的业务逻辑"
    )
    private BatchCallbackHandler<T> batchCallbackHandler;
    @ApiModelProperty(
            required = false,
            value = "单次批量处理的条数，缺省值是100"
    )
    private int splitSize = 100;
    @ApiModelProperty(
            required = false,
            value = "每批数据处理出现失败时，重试的次数; 注意，需要确保你的代码以及下游调用方的代码是幂等的"
    )
    private int failRetryTime = 1;
    @ApiModelProperty(
            required = true,
            value = "每行excel的class类型。无法通过反射获取，原因参考 https://stackoverflow.com/a/3403969/4082598"
    )
    private Class<T> lineClass;

    public BatchProcessRequest() {
    }

    public String getExcelUrl() {
        return this.excelUrl;
    }

    public String getTaskId() {
        return this.taskId;
    }

    public BatchCallbackHandler<T> getBatchCallbackHandler() {
        return this.batchCallbackHandler;
    }

    public int getSplitSize() {
        return this.splitSize;
    }

    public int getFailRetryTime() {
        return this.failRetryTime;
    }

    public Class<T> getLineClass() {
        return this.lineClass;
    }

    public void setExcelUrl(final String excelUrl) {
        this.excelUrl = excelUrl;
    }

    public void setTaskId(final String taskId) {
        this.taskId = taskId;
    }

    public void setBatchCallbackHandler(final BatchCallbackHandler<T> batchCallbackHandler) {
        this.batchCallbackHandler = batchCallbackHandler;
    }

    public void setSplitSize(final int splitSize) {
        this.splitSize = splitSize;
    }

    public void setFailRetryTime(final int failRetryTime) {
        this.failRetryTime = failRetryTime;
    }

    public void setLineClass(final Class<T> lineClass) {
        this.lineClass = lineClass;
    }

    protected boolean canEqual(final Object other) {
        return other instanceof BatchProcessRequest;
    }

    public String toString() {
        return "BatchProcessRequest(excelUrl=" + this.getExcelUrl() + ", taskId=" + this.getTaskId() + ", batchCallbackHandler=" + this.getBatchCallbackHandler() + ", splitSize=" + this.getSplitSize() + ", failRetryTime=" + this.getFailRetryTime() + ", lineClass=" + this.getLineClass() + ")";
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        BatchProcessRequest<?> that = (BatchProcessRequest<?>) o;
        return splitSize == that.splitSize && failRetryTime == that.failRetryTime && Objects.equals(excelUrl, that.excelUrl) && Objects.equals(taskId, that.taskId) && Objects.equals(batchCallbackHandler, that.batchCallbackHandler) && Objects.equals(lineClass, that.lineClass);
    }

    @Override
    public int hashCode() {
        return Objects.hash(excelUrl, taskId, batchCallbackHandler, splitSize, failRetryTime, lineClass);
    }
}
